VERSION 5.00
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "RICHTX32.OCX"
Begin VB.Form frmVerifyAddress 
   BackColor       =   &H00FFFFFF&
   Caption         =   "Verify Address"
   ClientHeight    =   4890
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   9030
   Icon            =   "frmVerifyAddress.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   ScaleHeight     =   4890
   ScaleWidth      =   9030
   StartUpPosition =   1  'CenterOwner
   Begin VB.CommandButton cmdCancel 
      Appearance      =   0  'Flat
      BackColor       =   &H00E0E0E0&
      Caption         =   "Cancel"
      Height          =   320
      Left            =   3480
      MaskColor       =   &H0080C0FF&
      Style           =   1  'Graphical
      TabIndex        =   9
      TabStop         =   0   'False
      Top             =   4440
      UseMaskColor    =   -1  'True
      Width           =   1200
   End
   Begin VB.CommandButton cmdVerify 
      Appearance      =   0  'Flat
      BackColor       =   &H00C0E0FF&
      Caption         =   "Verify"
      Height          =   320
      Left            =   120
      MaskColor       =   &H0080C0FF&
      Style           =   1  'Graphical
      TabIndex        =   7
      TabStop         =   0   'False
      Top             =   4440
      UseMaskColor    =   -1  'True
      Width           =   1200
   End
   Begin VB.CommandButton cmdUpdate 
      Appearance      =   0  'Flat
      BackColor       =   &H00E0E0E0&
      Caption         =   "Update"
      Height          =   320
      Left            =   1800
      MaskColor       =   &H0080C0FF&
      Style           =   1  'Graphical
      TabIndex        =   8
      TabStop         =   0   'False
      Top             =   4440
      UseMaskColor    =   -1  'True
      Width           =   1200
   End
   Begin VB.Frame Frame2 
      BackColor       =   &H00FFFFFF&
      Caption         =   "Candidates"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H000080FF&
      Height          =   4155
      Left            =   4860
      TabIndex        =   13
      Top             =   120
      Width           =   4035
      Begin VB.CommandButton cmdSelect 
         BackColor       =   &H00E0E0E0&
         Caption         =   "Select"
         Height          =   315
         Index           =   1
         Left            =   120
         Style           =   1  'Graphical
         TabIndex        =   10
         Top             =   1200
         Width           =   1035
      End
      Begin VB.CommandButton cmdSelect 
         BackColor       =   &H00E0E0E0&
         Caption         =   "Select"
         Height          =   315
         Index           =   2
         Left            =   120
         Style           =   1  'Graphical
         TabIndex        =   12
         Top             =   3120
         Width           =   1035
      End
      Begin RichTextLib.RichTextBox txtCandidate 
         Height          =   1215
         Index           =   2
         Left            =   1260
         TabIndex        =   24
         TabStop         =   0   'False
         Top             =   2220
         Width           =   2595
         _ExtentX        =   4577
         _ExtentY        =   2143
         _Version        =   393217
         TextRTF         =   $"frmVerifyAddress.frx":1272
      End
      Begin RichTextLib.RichTextBox txtCandidate 
         Height          =   1155
         Index           =   1
         Left            =   1260
         TabIndex        =   23
         TabStop         =   0   'False
         Top             =   360
         Width           =   2595
         _ExtentX        =   4577
         _ExtentY        =   2037
         _Version        =   393217
         TextRTF         =   $"frmVerifyAddress.frx":12F4
      End
      Begin VB.Label lblMessage 
         Alignment       =   2  'Center
         BackColor       =   &H00FFFFFF&
         Height          =   615
         Index           =   2
         Left            =   1260
         TabIndex        =   27
         Top             =   3480
         Width           =   2595
      End
      Begin VB.Label lblMessage 
         Alignment       =   2  'Center
         BackColor       =   &H00FFFFFF&
         Height          =   615
         Index           =   1
         Left            =   1260
         TabIndex        =   26
         Top             =   1560
         Width           =   2595
      End
   End
   Begin VB.Frame Frame1 
      BackColor       =   &H00FFFFFF&
      Caption         =   "Recipient Address"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H000080FF&
      Height          =   4155
      Left            =   120
      TabIndex        =   11
      Top             =   120
      Width           =   4575
      Begin VB.TextBox txtCompany 
         Height          =   315
         Left            =   1440
         TabIndex        =   1
         Top             =   1140
         Width           =   2955
      End
      Begin VB.TextBox txtAddressLine1 
         Height          =   315
         Left            =   1440
         TabIndex        =   2
         Top             =   1500
         Width           =   2955
      End
      Begin VB.TextBox txtAddressLine2 
         Height          =   315
         Left            =   1440
         TabIndex        =   3
         Top             =   1860
         Width           =   2955
      End
      Begin VB.TextBox txtCity 
         Height          =   315
         Left            =   1440
         TabIndex        =   4
         Top             =   2220
         Width           =   2955
      End
      Begin VB.TextBox txtState 
         Height          =   315
         Left            =   1440
         TabIndex        =   5
         Top             =   2580
         Width           =   2955
      End
      Begin VB.TextBox txtZip 
         Height          =   315
         Left            =   1440
         TabIndex        =   6
         Top             =   2940
         Width           =   2955
      End
      Begin VB.TextBox txtContact 
         Height          =   315
         Left            =   1440
         TabIndex        =   0
         Top             =   780
         Width           =   2955
      End
      Begin VB.Label lblStatus 
         Alignment       =   2  'Center
         BackColor       =   &H00FFFFFF&
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H000000C0&
         Height          =   255
         Left            =   1440
         TabIndex        =   25
         Top             =   3540
         Width           =   1635
      End
      Begin VB.Label lblRecipientID 
         BackColor       =   &H00FFFFFF&
         Height          =   255
         Left            =   1440
         TabIndex        =   22
         Top             =   480
         Width           =   2955
      End
      Begin VB.Label Label8 
         Alignment       =   1  'Right Justify
         BackColor       =   &H00FFFFFF&
         Caption         =   "State:"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   21
         Top             =   2640
         Width           =   1095
      End
      Begin VB.Label Label7 
         Alignment       =   1  'Right Justify
         BackColor       =   &H00FFFFFF&
         Caption         =   "Zip:"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   20
         Top             =   3000
         Width           =   1095
      End
      Begin VB.Label Label6 
         Alignment       =   1  'Right Justify
         BackColor       =   &H00FFFFFF&
         Caption         =   "Address 1:"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   19
         Top             =   1560
         Width           =   1095
      End
      Begin VB.Label Label5 
         Alignment       =   1  'Right Justify
         BackColor       =   &H00FFFFFF&
         Caption         =   "Address 2:"
         Height          =   255
         Left            =   240
         TabIndex        =   18
         Top             =   1920
         Width           =   1095
      End
      Begin VB.Label Label4 
         Alignment       =   1  'Right Justify
         BackColor       =   &H00FFFFFF&
         Caption         =   "City:"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   17
         Top             =   2280
         Width           =   1095
      End
      Begin VB.Label Label3 
         Alignment       =   1  'Right Justify
         BackColor       =   &H00FFFFFF&
         Caption         =   "Company:"
         Height          =   255
         Left            =   240
         TabIndex        =   16
         Top             =   1200
         Width           =   1095
      End
      Begin VB.Label Label2 
         Alignment       =   1  'Right Justify
         BackColor       =   &H00FFFFFF&
         Caption         =   "Contact:"
         Height          =   255
         Left            =   240
         TabIndex        =   15
         Top             =   840
         Width           =   1095
      End
      Begin VB.Label Label1 
         Alignment       =   1  'Right Justify
         BackColor       =   &H00FFFFFF&
         Caption         =   "Recipient ID:"
         Height          =   255
         Left            =   240
         TabIndex        =   14
         Top             =   480
         Width           =   1095
      End
   End
End
Attribute VB_Name = "frmVerifyAddress"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'****************************************************************************
'*                                                                          *
'*  Application:    Address Verification Prototype for Cafe (FXI)           *
'*  Module:         frmVerifyAddress                                        *
'*                                                                          *
'*  Author:         Chris Marsh                                             *
'*                  Customer Systems Development Consulting                 *
'*                  FedEx Services                                          *
'*                                                                          *
'*  Description:    Form retrieves and displays Address from Cafe or from   *
'*                  the Verify Address Book form.                           *
'*                  Address may then be verified using the FedEx gateway    *
'*                  (XML).  The user has the option of iterating through    *
'*                  the verification process until he is satisfied with the *
'*                  result, at which point he may accept the modifications. *
'*                                                                          *
'*                  Copyright 2004 FedEx Services                           *
'*                                                                          *
'****************************************************************************
'*                    M A I N T E N A N C E   L O G                         *
'*--------------------------------------------------------------------------*
'* Date       | Programmer | Description                                    *
'*--------------------------------------------------------------------------*
'* 07/01/2004 | Chris Marsh  | Initial Development                            *
'* 08/05/2004 | Chris Marsh  | Release 2 Initial Development                  *
'* 09/07/2004 | Chris Marsh  | Implement standardizations                     *
'* 09/09/2004 | Chris Elwell | Modified to fit NASCAR                                             *
'****************************************************************************

Option Explicit

Const MODULE_NAME As String = "frmVerifyAddress"

Const MAX_CANDIDATES = 2

Dim m_strContactName(MAX_CANDIDATES) As String
Dim m_strCompanyName(MAX_CANDIDATES) As String
Dim m_strAddress1(MAX_CANDIDATES) As String
Dim m_strAddress2(MAX_CANDIDATES) As String
Dim m_strCity(MAX_CANDIDATES) As String
Dim m_strState(MAX_CANDIDATES) As String
Dim m_strZip(MAX_CANDIDATES) As String
' Use the following if International becomes supported
' Dim m_strCountry(MAX_CANDIDATES) As String
Dim m_strMessage(MAX_CANDIDATES) As String
Dim m_strCandidateText(MAX_CANDIDATES) As String



Private Sub cmdSelect_Click(Index As Integer)
    
    On Error GoTo ErrorHandle

    Const PROCEDURE_NAME As String = "cmdSelect_Click"
    
    UpdateAddressFromCandidate (Index)
    
    'Enable Update button and highlight
    cmdUpdate.BackColor = &HC0E0FF
    cmdUpdate.Enabled = True
    
    Exit Sub

ErrorHandle:

    MsgBox Err.Description, vbCritical Or vbSystemModal, MODULE_NAME & "." & PROCEDURE_NAME

End Sub

Private Sub Form_Activate()
    
    On Error GoTo ErrorHandle

    Const PROCEDURE_NAME As String = "Form_Initialize"

    cmdUpdate.Enabled = False
    HideCandidate (1)
    HideCandidate (2)
    GetAddressFromShip
    
    txtContact.SetFocus
    
    Exit Sub

ErrorHandle:

    MsgBox Err.Description, vbCritical Or vbSystemModal, MODULE_NAME & "." & PROCEDURE_NAME

End Sub
'---------------------------------------------------------------------------------------
' Procedure : Form_KeyDown()
' DateTime  : 2/17/2005
' Purpose   : Enter key pressed sends a TAB to move to next field
'---------------------------------------------------------------------------------------
'
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If Not TypeOf Me.ActiveControl Is CommandButton Then
        If Shift = 0 And KeyCode = 13 Then
            SendKeys "{TAB}"
        End If
    End If
End Sub
'****************************************************************************
'*                                                                          *
'****************************************************************************
Private Sub cmdUpdate_Click()

    On Error GoTo ErrorHandle

    Const PROCEDURE_NAME As String = "cmdUpdate_Click"
    
    SendAddressToShip
    
    Unload Me

    Exit Sub

ErrorHandle:

    MsgBox Err.Description, vbCritical Or vbSystemModal, MODULE_NAME & "." & PROCEDURE_NAME

End Sub


'****************************************************************************
'*                                                                          *
'****************************************************************************
Private Sub cmdCancel_Click()

    On Error GoTo ErrorHandle

    Const PROCEDURE_NAME As String = "cmdCancel_Click"
    
    Unload Me
    frmShip.SetFocus
    
    Exit Sub

ErrorHandle:

    MsgBox Err.Description, vbCritical Or vbSystemModal, MODULE_NAME & "." & PROCEDURE_NAME

End Sub


'****************************************************************************
'*                                                                          *
'****************************************************************************
Private Sub cmdVerify_Click()

    On Error GoTo ErrorHandle

    Const PROCEDURE_NAME As String = "cmdVerify_Click"
    
    Dim strRequestXML As String
    Dim strResponseXML As String

    Dim intMatchCount As Integer
    Dim intIndex As Integer

    'Initially disable Select buttons and RTBs
    Call HideCandidate(1)
    Call HideCandidate(2)
    lblStatus.Caption = "Searching..."
    Me.Refresh
    
    strRequestXML = CreateGatewayRequestXML(txtCompany.Text, _
                                            txtAddressLine1.Text, _
                                            txtAddressLine2.Text, _
                                            txtCity.Text, _
                                            txtState.Text, _
                                            txtZip.Text)

    strResponseXML = SendAddressRequestToGateway(strRequestXML)

    intMatchCount = GetMatchCount(strResponseXML)

    If intMatchCount = 0 Then
        lblMessage(1).Visible = True
        lblMessage(1).Caption = "Unable to verify address.  Please try again."
    Else
        For intIndex = 1 To intMatchCount
            GetCandidate intIndex, strResponseXML
            ShowCandidate intIndex, m_strCandidateText(intIndex), m_strMessage(intIndex)
        Next
    End If

    lblStatus.Caption = "Complete."

    Exit Sub

ErrorHandle:

    MsgBox Err.Description, vbCritical Or vbSystemModal, MODULE_NAME & "." & PROCEDURE_NAME

End Sub


'****************************************************************************
'*                                                                          *
'****************************************************************************
Private Sub ShowCandidate(ByVal intIndex As Integer, _
                          ByVal strCandidateText As String, _
                          ByVal strMessageText As String)

    On Error GoTo ErrorHandle

    Const PROCEDURE_NAME As String = "ShowCandidate"
    
    cmdSelect(intIndex).Enabled = True
    txtCandidate(intIndex).Enabled = True
    lblMessage(intIndex).Visible = True
    txtCandidate(intIndex).TextRTF = strCandidateText
    lblMessage(intIndex).Caption = strMessageText

    Exit Sub

ErrorHandle:

    MsgBox Err.Description, vbCritical Or vbSystemModal, MODULE_NAME & "." & PROCEDURE_NAME

End Sub
'****************************************************************************
'*                                                                          *
'****************************************************************************
Private Sub HideCandidate(ByVal intIndex As Integer)
    
    On Error GoTo ErrorHandle
    
    Const PROCEDURE_NAME As String = "HideCandidate"
    
    cmdSelect(intIndex).Enabled = False
    txtCandidate(intIndex).Enabled = False
    lblMessage(intIndex).Visible = False

    Exit Sub

ErrorHandle:

    MsgBox Err.Description, vbCritical Or vbSystemModal, MODULE_NAME & "." & PROCEDURE_NAME

End Sub


'****************************************************************************
'*                                                                          *
'****************************************************************************
Private Sub GetAddressFromShip()

    On Error GoTo ErrorHandle
    
    Const PROCEDURE_NAME As String = "GetAddressFromShip"
    
    With frmShip
        lblRecipientID = .f1
        txtContact = .f12
        txtCompany = .f11
        txtAddressLine1 = .f13
        txtAddressLine2 = .f14
        txtCity = .f15
        txtState = .f16
        txtZip = .f17
    End With

    Exit Sub

ErrorHandle:

    MsgBox Err.Description, vbCritical Or vbSystemModal, MODULE_NAME & "." & PROCEDURE_NAME

End Sub
'****************************************************************************
'*                                                                          *
'****************************************************************************
Private Sub SendAddressToShip()

    On Error GoTo ErrorHandle
    
    Const PROCEDURE_NAME As String = "SendAddressToShip"
    
    With frmShip
        .f12 = txtContact.Text
        .f11 = txtCompany.Text
        .f13 = txtAddressLine1.Text
        .f14 = txtAddressLine2.Text
        .f15 = txtCity.Text
        .f16 = txtState.Text
        .f17 = txtZip.Text
    End With
    
    Exit Sub

ErrorHandle:

    MsgBox Err.Description, vbCritical Or vbSystemModal, MODULE_NAME & "." & PROCEDURE_NAME

End Sub
'****************************************************************************
'*                                                                          *
'****************************************************************************
Private Sub UpdateAddressFromCandidate(ByVal intIndex As Integer)

    On Error GoTo ErrorHandle
    
    Const PROCEDURE_NAME As String = "UpdateAddressFromCandidate"
    
    txtAddressLine1.Text = m_strAddress1(intIndex)
    
    If m_strAddress2(intIndex) <> "" Then
        txtAddressLine2.Text = m_strAddress2(intIndex)
    End If
    
    txtCity.Text = m_strCity(intIndex)
    txtState.Text = m_strState(intIndex)
    txtZip.Text = m_strZip(intIndex)

    Exit Sub

ErrorHandle:

    MsgBox Err.Description, vbCritical Or vbSystemModal, MODULE_NAME & "." & PROCEDURE_NAME

End Sub
'****************************************************************************
'*                                                                          *
'****************************************************************************
Private Sub GetCandidate(ByVal intIndex As Integer, _
                         ByVal strResponseXML As String)

    On Error GoTo ErrorHandle
    
    Const PROCEDURE_NAME As String = "GetCandidate"
    
    Dim objXMLDOM As MSXML2.DOMDocument30
    Dim objXMLNodes As MSXML2.IXMLDOMNodeList
    Dim objXMLNode As MSXML2.IXMLDOMNode

    Set objXMLDOM = New DOMDocument30

    objXMLDOM.loadXML strResponseXML

    Set objXMLNodes = objXMLDOM.selectNodes("//.//Match")

    m_strContactName(intIndex) = txtContact.Text
    m_strCompanyName(intIndex) = txtCompany.Text
    m_strAddress1(intIndex) = ExtractNodeValue(objXMLNodes.item(intIndex - 1).selectSingleNode(".//Line1"))
    m_strAddress1(intIndex) = ExtractNodeValue(objXMLNodes.item(intIndex - 1).selectSingleNode(".//Line1"))
    m_strAddress2(intIndex) = ExtractNodeValue(objXMLNodes.item(intIndex - 1).selectSingleNode(".//Line2"))
    m_strCity(intIndex) = ExtractNodeValue(objXMLNodes.item(intIndex - 1).selectSingleNode(".//City"))
    m_strState(intIndex) = ExtractNodeValue(objXMLNodes.item(intIndex - 1).selectSingleNode(".//StateOrProvinceCode"))
    m_strZip(intIndex) = ExtractNodeValue(objXMLNodes.item(intIndex - 1).selectSingleNode(".//PostalCode"))
    m_strMessage(intIndex) = ExtractNodeValue(objXMLNodes.item(intIndex - 1).selectSingleNode(".//SoftError/Message"))

    If m_strMessage(intIndex) = "" Then
        m_strMessage(intIndex) = "Valid."
    End If

    m_strCandidateText(intIndex) = FormatCandidateText(m_strContactName(intIndex), _
                                                       m_strCompanyName(intIndex), _
                                                       m_strAddress1(intIndex), _
                                                       m_strAddress2(intIndex), _
                                                       m_strCity(intIndex), _
                                                       m_strState(intIndex), _
                                                       m_strZip(intIndex))
    
    Set objXMLNode = Nothing
    Set objXMLNodes = Nothing
    Set objXMLDOM = Nothing

    Exit Sub

ErrorHandle:

    MsgBox Err.Description, vbCritical Or vbSystemModal, MODULE_NAME & "." & PROCEDURE_NAME

    Set objXMLNode = Nothing
    Set objXMLNodes = Nothing
    Set objXMLDOM = Nothing
    
End Sub


'****************************************************************************
'*                                                                          *
'****************************************************************************
Private Function FormatCandidateText(ByVal strContactName As String, _
                                     ByVal strCompanyName As String, _
                                     ByVal strAddress1 As String, _
                                     ByVal strAddress2 As String, _
                                     ByVal strCity As String, _
                                     ByVal strState As String, _
                                     ByVal strZip As String) As String

    On Error GoTo ErrorHandle

    Const PROCEDURE_NAME As String = "FormatCandidateText"
    
    strContactName = "{ " & strContactName & "\line}"
    strCompanyName = "{ " & strCompanyName & "\line}"

    If strAddress1 = txtAddressLine1.Text Then
        strAddress1 = "{ " & strAddress1 & "\line}"
    Else
        strAddress1 = "{\b\ " & strAddress1 & "\line}"
    End If

    If strAddress2 = txtAddressLine2.Text Then
        strAddress2 = "{ " & strAddress2 & "\line}"
    Else
        strAddress2 = "{\b\ " & strAddress2 & "\line}"
    End If

    If strCity = txtCity.Text Then
        strCity = "{ " & strCity & "}"
    Else
        strCity = "{\b\ " & strCity & "}"
    End If

    If strState = txtState.Text Then
        strState = "{ " & strState & "}"
    Else
        strState = "{\b\ " & strState & "}"
    End If

    If strZip = txtZip.Text Then
        strZip = "{ " & strZip & "}"
    Else
        strZip = "{\b\ " & strZip & "}"
    End If

    FormatCandidateText = "{" & _
                            strContactName & _
                            strCompanyName & _
                            strAddress1 & _
                            strAddress2 & _
                            strCity & ", " & strState & "  " & strZip & _
                            "}"

    Exit Function

ErrorHandle:

    MsgBox Err.Description, vbCritical Or vbSystemModal, MODULE_NAME & "." & PROCEDURE_NAME

End Function
